package hw048901.lesson1;

import java.util.ArrayList;
import java.util.List;

public class TPrintCls<T> {
	private  T to;
	public T getTo() {
		return to;
	}

	public void setTo(T to) {
		this.to = to;
	}
	
	public TPrintCls(T to){this.to=to;}
	public TPrintCls(){this.to=to;}
	public void printC(List list,int pi)
	{
		{
			int j;
			try {
				for (j = 0; j < pi ; j++) {
					System.out.print(list.get(j).toString().concat("  "));
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	public boolean BreakC(List l,Integer o1)
	{
		   boolean isBreak=false;
		   int j;
		   try
		   {
		    for (j=0;j<l.size()-1;j++)
		    {
			    	if (o1.equals(l.get(j))) 
			    	{
			    		isBreak = true;
			    		break;
			    	}
			    }
		    
		   } 
		   catch(Exception e)
		   {
			   e.printStackTrace();
			  
		   }
		   return isBreak;  
	}	
	public static  void  main(String[] args)
	{
		boolean ib;
		int i,j;
		try {
			//数据准备
			ArrayList<Integer> a;
			a = new ArrayList();
			j=100;
			for (i=1;i<=j;i++)
			{
				a.add(i);
			}	
			//调用方法
			TPrintCls<TPrintClsInt> tpo =null;
			TPrintCls<List> tpl =null;
			TPrintClsInt pcIo=null;
			System.out.println("\n method 1 make the TPrintClsInt as T instance  \n" );
			pcIo = new TPrintClsInt(a);
			//tpo =  (TPrintCls<TPrintClsInt>) new TPrintCls<TPrintClsInt>(pcIo);
			tpo =  (TPrintCls<TPrintClsInt>) new TPrintCls<TPrintClsInt>();
			tpo.setTo(pcIo);
			// piIo method
			System.out.println("\n method 2call the  TPrintCls's method  \n" );
			tpo.printC(a, 100);
			System.out.println("\n call the  TPrintClsInt method in the class TPrintCls \n" );
			tpo.getTo().printCInt(a, 100);
			System.out.println("\n");
			ib = tpo.getTo().BreakCInt((Integer) 47);
			if(ib)
			{
				System.out.println("find the objecdt 47 break success!");
			}
			else
			{
				System.out.println("not find the objecdt 47 break failed!");
			}
			//method 4
			System.out.println("method 4 in the class = " .concat(pcIo.getClass().getName()));
			pcIo.printCInt(pcIo.getListInt(), (Integer)100);
			System.out.println("\n");
			ib = pcIo.BreakCInt((Integer) 47);
			if(ib)
			{
				System.out.println("find the objecdt 47 break success!");
			}
			else
			{
				System.out.println("not find the objecdt 47 break failed!");
			}			
			//method 5
			System.out.println("\n method 5 make the ArrayList as T instance  \n" );
			tpl = (TPrintCls<List>) new TPrintCls<List>();
			tpl.printC(a, 100);
			System.out.println("\n");
			ib = tpl.BreakC(a,(Integer) 47);
			if(ib)
			{
				System.out.println("find the objecdt 47 break success!");
			}
			else
			{
				System.out.println("not find the objecdt 47 break failed!");
			}			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}

	}
}
